<?php

/**
 * Html form for user login
 *
 * @file
 * @ingroup Templates
 */
/**
 * @defgroup Templates Templates
 */
if (!defined('MEDIAWIKI'))
    die(-1);

/**
 * HTML template for Special:Userlogin form
 * @ingroup Templates
 */
class TemplateUserFriends extends QuickTemplate {
    
    /**
     *
     * @var type 
     */
    private $user;
    private $rows;
    private $rows2;
    private $nom;
    private $id_connecte;
    private $deja_ami=false;
    /**
     *
     * @param type $user
     * @param type $rows 
     */
    function __construct($user, $rows, $rows2, $id_user_connecte) {
        parent::__construct();
        $this->user = $user;
        $this->rows = $rows;
        $this->rows2 = $rows2;
        $this->id_connecte = $id_user_connecte;
        
        $data=array();
    }
    
    /**
     * 
     * @param type $nom 
     */
    public function setNom($nom){
        $this->nom = $nom;
    }
    
    function execute() {
        
        echo "<h2>Liste des utilisateurs</h2><br/>";
       
    ?>
    
    <?php
    
        if($this->id_connecte != NULL)
        {
            
        ?><ul>
        
            <?php
        
            foreach($this->rows as $key=>$val){
            
                ?>
                
                <form method="POST" action='http://www.solidaritychain.com.dev/index.php?title=Special:FriendsAjout' />
            
                <li><a href='http://www.solidaritychain.com.dev/index.php/Spécial:Profil?user_name=<?php echo $val->user_name?>'><?php echo($val->user_name)?></a>
                     <input type='hidden' name='idUserFriend' value="<?php echo($val->user_id); ?>"/>
                     <input type='hidden' name='user_name' value="<?php echo($val->user_name); ?>"/>
                     
                     <?php
                     foreach($this->rows2 as $key=>$val2){
            
                        if(($val->user_id)==($val2->user_id_friends))
                        {
                            $this->deja_ami = true;
                        }
                      }?>
                     <?php if($this->deja_ami==false)
                     { ?>
                        <input type='submit' value='Ajouter comme ami'/>
                     <?php
                     }
                     else
                     {
                        echo "(Déjà ami)";
                     }
                     $this->deja_ami=false;
                     ?>
                </li>
                
                </form> 
            <?php
            }
        ?>
       
        </ul><?php
        }
        
        else
        {
            echo("Vous devez être connecté pour voir cette page.");
        }
    }
}
